/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package reflection;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Nguyen Minh Tan
 */
public class LoadClassFromPackageInSystemDisk {
    public LoadClassFromPackageInSystemDisk() {
        try {
            //Xem thêm trong java help phần class JarURLConnection
            URL myurl[] = {new URL("jar:file:///G:/NetBeansProjects/J2SE/LearnJava/data/HelloPackage.jar!/")};
            URLClassLoader loader = new URLClassLoader(myurl);
            Class c = loader.loadClass("hellopackage.HelloMainClass");
            Object obj = c.newInstance();
            //Load 1 method của 1 đối tượng
            Method fi1 = c.getDeclaredMethod("inramanhinh");
            //Tương đương dùng
            Method fi2 = obj.getClass().getDeclaredMethod("inramanhinh");
            fi1.invoke(obj);
            fi2.invoke(obj);
        } catch (Exception ex) {
            Logger.getLogger(LoadClassFromSystemDisk.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    /*
    public static void main(String args[]){
        new LoadClassFromPackageInSystemDisk();
    }
     * **/
}
